package o;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable.Callback;
import android.graphics.drawable.Drawable.ConstantState;
import android.view.Gravity;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import com.bumptech.glide.Glide;
import com.bumptech.glide.gifdecoder.GifDecoder;
import java.nio.ByteBuffer;
import java.util.List;
import o.oq.d;

public class xt extends Drawable implements o.xv.b, Animatable, oq {
    private Rect ʻ;
    private int ʼ;
    private Paint ʽ;
    private boolean ˊ;
    private boolean ˋ;
    private List<d> ˋॱ;
    private final b ˎ;
    private boolean ˏ;
    private boolean ॱ;
    private int ॱॱ;
    private boolean ᐝ;

    static final class b extends ConstantState {
        @VisibleForTesting
        final xv ˋ;

        b(xv xvVar) {
            this.ˋ = xvVar;
        }

        @NonNull
        public Drawable newDrawable(Resources resources) {
            return newDrawable();
        }

        @NonNull
        public Drawable newDrawable() {
            return new xt(this);
        }

        public int getChangingConfigurations() {
            return 0;
        }
    }

    public xt(Context context, GifDecoder gifDecoder, si<Bitmap> siVar, int i, int i2, Bitmap bitmap) {
        this(new b(new xv(Glide.ˎ(context), gifDecoder, i, i2, siVar, bitmap)));
    }

    xt(b bVar) {
        this.ˋ = true;
        this.ॱॱ = -1;
        this.ˎ = (b) aas.ˎ(bVar);
    }

    public int ˏ() {
        return this.ˎ.ˋ.ˋ();
    }

    public Bitmap ˎ() {
        return this.ˎ.ˋ.ˊ();
    }

    public void ॱ(si<Bitmap> siVar, Bitmap bitmap) {
        this.ˎ.ˋ.ˎ(siVar, bitmap);
    }

    public ByteBuffer ॱ() {
        return this.ˎ.ˋ.ʻ();
    }

    public int ˊ() {
        return this.ˎ.ˋ.ʽ();
    }

    public int ˋ() {
        return this.ˎ.ˋ.ˎ();
    }

    private void ʼ() {
        this.ʼ = 0;
    }

    public void start() {
        this.ˊ = true;
        ʼ();
        if (this.ˋ) {
            ॱॱ();
        }
    }

    public void stop() {
        this.ˊ = false;
        ʽ();
    }

    private void ॱॱ() {
        aas.ˏ(!this.ˏ, "You cannot start a recycled Drawable. Ensure thatyou clear any references to the Drawable when clearing the corresponding request.");
        if (this.ˎ.ˋ.ʽ() == 1) {
            invalidateSelf();
        } else if (!this.ॱ) {
            this.ॱ = true;
            this.ˎ.ˋ.ˋ(this);
            invalidateSelf();
        }
    }

    private void ʽ() {
        this.ॱ = false;
        this.ˎ.ˋ.ˏ((o.xv.b) this);
    }

    public boolean setVisible(boolean z, boolean z2) {
        aas.ˏ(!this.ˏ, "Cannot change the visibility of a recycled resource. Ensure that you unset the Drawable from your View before changing the View's visibility.");
        this.ˋ = z;
        if (!z) {
            ʽ();
        } else if (this.ˊ) {
            ॱॱ();
        }
        return super.setVisible(z, z2);
    }

    public int getIntrinsicWidth() {
        return this.ˎ.ˋ.ॱ();
    }

    public int getIntrinsicHeight() {
        return this.ˎ.ˋ.ˏ();
    }

    public boolean isRunning() {
        return this.ॱ;
    }

    protected void onBoundsChange(Rect rect) {
        super.onBoundsChange(rect);
        this.ᐝ = true;
    }

    public void draw(@NonNull Canvas canvas) {
        if (!this.ˏ) {
            if (this.ᐝ) {
                Gravity.apply(119, getIntrinsicWidth(), getIntrinsicHeight(), getBounds(), ˏॱ());
                this.ᐝ = false;
            }
            canvas.drawBitmap(this.ˎ.ˋ.ʼ(), null, ˏॱ(), ˊॱ());
        }
    }

    public void setAlpha(int i) {
        ˊॱ().setAlpha(i);
    }

    public void setColorFilter(ColorFilter colorFilter) {
        ˊॱ().setColorFilter(colorFilter);
    }

    private Rect ˏॱ() {
        if (this.ʻ == null) {
            this.ʻ = new Rect();
        }
        return this.ʻ;
    }

    private Paint ˊॱ() {
        if (this.ʽ == null) {
            this.ʽ = new Paint(2);
        }
        return this.ʽ;
    }

    public int getOpacity() {
        return -2;
    }

    private Callback ͺ() {
        Callback callback = getCallback();
        while (callback instanceof Drawable) {
            callback = ((Drawable) callback).getCallback();
        }
        return callback;
    }

    public void ʻ() {
        if (ͺ() == null) {
            stop();
            invalidateSelf();
            return;
        }
        invalidateSelf();
        if (ˋ() == ˊ() - 1) {
            this.ʼ++;
        }
        if (this.ॱॱ != -1 && this.ʼ >= this.ॱॱ) {
            ॱˊ();
            stop();
        }
    }

    private void ॱˊ() {
        if (this.ˋॱ != null) {
            int size = this.ˋॱ.size();
            for (int i = 0; i < size; i++) {
                ((d) this.ˋॱ.get(i)).ˎ(this);
            }
        }
    }

    public ConstantState getConstantState() {
        return this.ˎ;
    }

    public void ᐝ() {
        this.ˏ = true;
        this.ˎ.ˋ.ॱॱ();
    }
}
